import axios from 'axios';
const http = axios.create({
    baseURL:'/api'
})

//请求拦截器 一般用来传递头部(token)参数
http.interceptors.request.use(req => {
    if (req.url == "/cartlist" || req.url == '/cartadd' || req.url == '/cartedit' || req.url == "/cartdelete") {
        // req.headers.authorization = req.params.authorization
        req.headers.authorization = JSON.parse(localStorage.getItem('user')).token
    }
    if (req.url == '/orderadd') {
        req.headers.authorization = JSON.parse(localStorage.getItem('user')).token;
        req.headers.contentType = application/json
    }
    return req
})
//响应拦截器 方便返回一个更简便的数组
http.interceptors.response.use(res => {
    return res.data
})


export default http